<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%
    Integer uid = token.getUid();
    List<Map> visits = QBuilder.db("basedb").select("new map(v.id as visit_id, v.name as patient_name, v.isconfirmed as confirm, v.surveyId as survey_id, s.title as title, v.score as score)").from("Visit as v, Survey as s").where(new Where("v.hospital=", hospital).and("v.status = ", STATUS_ENABLE).and("s.hospital=", hospital).and("v.category=3").and("s.category=3").and("v.patientUid=", uid).and("s.id = v.surveyId")).order("v.cTime", QBuilder.desc).query().getResultObj();
    if (isEmpty(visits)) {
        msg = new Message(30041, "暂未参与任何健康评测");
        msg.put("data", new ArrayList());
        Tools.encryptPrint(out, msg);
        return;
    }
    String surveyIds = "-1";
    for (int i = 0; i < visits.size(); i++) {
        Map map = (Map)visits.get(i);
        int surveyId = Tools.getInt(map.get("survey_id") + "", -99999);
        if (surveyId == -99999) continue;
        surveyIds += ("," + surveyId);
    }
    List<SurveyScore> scores = QBuilder.db("basedb").queryHql("from SurveyScore where sid in (" + surveyIds + ")");
    for (int i = 0; i < visits.size(); i++) {
        Map map = (Map)visits.get(i);
        int surveyId = Tools.getInt(map.get("survey_id") + "", -99999);
        int score = Tools.getInt(map.get("score") + "", 0);
        map.put("content", "");
        for (int j = 0; j < scores.size(); j++) {
            SurveyScore surveyScore = scores.get(j);
            if (surveyId == surveyScore.getSid() && score >= surveyScore.getMin() && score <= surveyScore.getMax()) {
                map.put("content", surveyScore.getContent());
                break;
            }
        }
    }
    msg.put("data", visits);
    Tools.encryptPrint(out, msg);
%>
